Conda¶
miniconda is a light version of anaconda,
it contains only conda, python and other necessary tools.
miniforge is similar to minicoda
but conda-forge is the only channel by default.
miniconda has package installer while
miniforge has only command installer.
Use conda-forge channel instead of defaults channel
when installing packages and
use pip only when conda doesn't have certain packages.
Install conda¶
First, go to
miniconda installer,
download macos.pkg and install it.
Second, check if conda is configured using conda --version.
If not, it needs to be configured in file .zshrc
(a place for personal configurations):
- Open this file in terminal using
vim ~/.zshrc, - Type
ito open edit mode (--INSERT-- will appear at bottom), - Write
export PATH=/Users/chengfengliu/Softwares/miniconda3/bin:$PATHin a new line, - Press
escto close edit mode, - Move the cursor to end and type
:(:will appear at bottom), typewq(add!if there is readonly problem) after:and pressenterto close.zshrc, - Make the edited configurations effective using
source ~/.zshrc, - Check again using
conda --version.
Third, set conda-forge as the only channel:
- Check current channels with priorities
using
conda config --get channels, - Add
conda-forgechannel with the highest priority usingconda config --add channels conda-forge, - Set channel priority strict
using
conda config --set channel_priority strict, - Remove
defaultschannel usingconda config --remove channels defaults, - Check again using
conda config --get channels, - In
baseenv, update all packages fromdefaultschannel toconda-forgechannel usingconda update --all, - Check by
conda list.
If xcrun error occurs, use xcode-select --install.
Conda commands¶
conda --version
conda list
conda search --full-name pkg_precise
conda search pkg_pattern
conda install pkg=version
conda uninstall pkg
conda update conda
conda update pkg=version
conda update --all
conda create --name env python=version
conda create --name env1 --clone env2
conda activate env
conda deactivate
conda env list
conda env remove --name env
conda config --get channels
conda config --add channels channel
conda config --set channel_priority strict
conda config --remove channels channel
Pip¶
Install pip¶
Installing python using conda when creating an env comes with pip.
Mac uses zsh in terminal which
causes no matches found issue with spuare brackets,
solution follows:
- Open
.zshrcfile in terminal usingvim ~/.zshrc, - Type
ito open edit mode (--INSERT-- will appear at bottom), - Write
setopt no_nomatchin a new line, - Press
escto close edit mode, - Move the cursor to end and type
:(:will appear at bottom), typewq(add!if there is readonly problem) after:and pressenterto close.zshrc, - Make the edited configurations effective using
source ~/.zshrc.
Pip commands¶
pip --version
pip list
pip list --outdated
pip check pkg
pip check
pip install pkg==version
pip install --upgrade pip
pip install --upgrade pkg==version
pip uninstall pkg
pip freeze
pip freeze > requirements.txt
pip install -r requirements.txt
Environments¶
Using Jupyter extension in VSCode doesn't require Jupyter Lab or Notebook installed because they are user interfaces just like VSCode, but the following packages are needed:
ipykernelconverts conda environments into kernels- nbconvert with pretty-jupyter exports Jupyter notebooks into htmls
Create data environment in base environment:
conda create --name data ipykernel \
python python-docx pandas openpyxl \
scikit-learn py-xgboost lightgbm catboost optuna \
langchain openai transformers \
plotly nbconvert
pip install pretty-jupyter
To activate data environment and enter into Projects directory
when launching terminal:
- Open
.zshrcfile in terminal usingvim ~/.zshrc, - Type
ito open edit mode (--INSERT-- will appear at bottom), - Write
conda activate dataandcd /Users/chengfengliu/Documents/Projectsin separated new lines, - Press
escto close edit mode, - Move the cursor to end and type
:(:will appear at bottom), typewq(add!if there is readonly problem) after:and pressenterto close.zshrc, - Make the edited configurations effective using
source ~/.zshrc.
I am chengfengliu